/* __auth__ : KunLin */

package com.cskaoyan.gateway.controller.shopping;


import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.order.constant.OrderRetCode;
import com.mall.shopping.ICartService;
import com.mall.shopping.IProductService;
import com.mall.shopping.dto.*;
import com.mall.user.constants.SysRetCodeConstants;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/shopping")
public class ItemsController {

    @Reference(timeout = 3000,retries = 2, check = false)
    ICartService iCartService;

    @Reference(timeout = 3000,retries = 2, check = false)
    IProductService productService;

    @RequestMapping(value = {"/items/{uid}"}, method = {RequestMethod.DELETE})
    @ResponseBody
    public ResponseData<DeleteCheckedItemResposne> deleteCheckedItem(@PathVariable("uid") Long uid, HttpServletRequest HttpRequest){
        DeleteCheckedItemRequest request = new DeleteCheckedItemRequest();
        request.setUserId(uid);

        DeleteCheckedItemResposne response = iCartService.deleteCheckedItem(request);


        if (OrderRetCode.SUCCESS.getCode().equals(response.getCode())){
            return new ResponseUtil<DeleteCheckedItemResposne>().setData(response);
        }
        return new ResponseUtil<DeleteCheckedItemResposne>().setErrorMsg(response.getMsg());
    }


    @RequestMapping(value = {"/items"}, method = {RequestMethod.PUT})
    @ResponseBody
    public ResponseData<CheckAllItemResponse> checkedAllItem(@RequestBody CheckAllItemRequest request, HttpServletRequest HttpRequest){

        CheckAllItemResponse response = iCartService.checkAllCartItem(request);




        if (OrderRetCode.SUCCESS.getCode().equals(response.getCode())){
            return new ResponseUtil<CheckAllItemResponse>().setData(response);
        }
        return new ResponseUtil<CheckAllItemResponse>().setErrorMsg(response.getMsg());
    }



}
